﻿Public Class frmSetup
    'Private m_frmNext As Form

    Private m_cIdou As New clsDbIdoHyo

    Private Sub frmSetup_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        frmInital.Enabled = False
        Me.Left = frmInital.Left - 15
        Me.Top = frmInital.Top + 10

        txtEquipID.Text = g_CURRENT_EQUIP_ID
        If Not String.IsNullOrEmpty(txtEquipID.Text) Then
            GetEquipInfo()
        End If
        txtBoxGotFocus(txtEquipID, e) 'ADD 苗 2018/3/23
    End Sub

    Private Sub frmSetup_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        'SelectWindow()

        'If m_frmNext.Visible = True Then
        '    m_frmNext.Activate()
        'Else
        '    m_frmNext.Show()
        '    frmInital.Height = 0
        '    frmInital.Width = 0
        'End If
        frmInital.Enabled = True
    End Sub

    Private Sub txtEquipID_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtEquipID.KeyPress
        '頭に付いている'%'を消す
        Static Dim fIsPercentInput As Boolean = False
        If e.KeyChar = CChar("%") OrElse e.KeyChar = CChar("％") Then
            fIsPercentInput = True
            e.Handled = True
            Exit Sub
        End If
        If fIsPercentInput Then
            fIsPercentInput = False
            e.Handled = True
            Exit Sub
        End If

        If e.KeyChar = vbCr Then
            GetEquipInfo()
            btnRegist.Focus()
        End If
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtEquipID.TextChanged
        lblEquipType.Text = String.Empty
        txtProcCD1.Text = String.Empty
        lblProcsCD.Text = String.Empty
    End Sub

    Private Sub btnEquipID_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEquipID.Click
        txtEquipID.Text = String.Empty
        txtProcCD1.Text = String.Empty
        txtEquipID.Focus()
    End Sub

    Private Sub btnRegist_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRegist.Click
        'ADD 苗 2018/3/23 begin
        If String.IsNullOrEmpty(txtPW.Text) Then
            MsgBox(getMsgStr("MSG00002", Label3.Text))
            txtPW.Focus()
            Exit Sub
        End If
        'ADD 苗 2018/3/23 end

        If txtPW.Text.Equals(m_cIdou.getPassword) Then 'ADD 苗 2018/3/23

            g_CURRENT_EQUIP_ID = txtEquipID.Text
            g_CURRENT_EQUIP_TYPE = m_cIdou.EquipInfo.iTypeCode
            PutIniFile("EQUIP", "EquipID", g_CURRENT_EQUIP_ID, g_szInitFileName)
            PutIniFile("EQUIP", "EquipType", g_CURRENT_EQUIP_TYPE.ToString, g_szInitFileName)
            'If g_CURRENT_EQUIP_TYPE = DEF_ID_KOHEN_DIESER_LINK AndAlso _
            '    MsgBox("一貫着工しますか？", MsgBoxStyle.YesNo, ) = MsgBoxResult.Yes Then
            '    '一貫着工の設定
            '    PutIniFile("EQUIP", "StartType", "1", g_szInitFileName)
            'Else
            '    PutIniFile("EQUIP", "StartType", "0", g_szInitFileName)
            'End If
            frmInital.btnStartComplt.Enabled = True
            frmInital.btnSwap.Enabled = True

            If chkSOCKET_FLAG.Enabled = True Then
                m_cIdou.updateSocketFLAG(chkSOCKET_FLAG.Checked, txtEquipID.Text)
            End If
            m_cIdou.updateKouteiCD1(txtProcCD1.Text.Trim.ToUpper, txtEquipID.Text)
            Me.Close()
        Else
            'ADD 苗 2018/3/23 Begin
            MsgBox(getMsgStr("MSG00004", Label3.Text))
            txtPW.SelectAll()
        End If
        'ADD 苗 2018/3/23 end
    End Sub

    Private Sub lblEquipType_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lblEquipType.TextChanged
        If Not String.IsNullOrEmpty(CType(sender, Label).Text) Then
            btnRegist.Enabled = True
        Else
            btnRegist.Enabled = False
        End If
    End Sub

    Private Sub GetEquipInfo()
        m_cIdou.GetEquipInfoByID(txtEquipID.Text)
        If String.IsNullOrEmpty(m_cIdou.EquipInfo.szEquipType) Then
            lblProcsCD.Text = String.Empty
            lblEquipType.Text = String.Empty
            Exit Sub
        End If
        lblProcsCD.Text = m_cIdou.EquipInfo.szKouteiCD
        lblEquipType.Text = m_cIdou.EquipInfo.szEquipType
        chkSOCKET_FLAG.Checked = m_cIdou.EquipInfo.iSocketFLAG
        txtProcCD1.Text = m_cIdou.EquipInfo.szKouteiCD1

        Dim objProc As New clsDbEquipMat
        Dim dt As DataTable

        For i As Integer = 0 To m_cIdou.ProcCdInfo.Length - 1
            dt = objProc.GetTitle(m_cIdou.ProcCdInfo(i))
            If IsNothing(dt) = False AndAlso dt.Rows.Count > 0 AndAlso dt(0)("RACK_FLOW_FLAG") = 1 Then
                chkSOCKET_FLAG.Enabled = True
                Exit Sub
            Else
                chkSOCKET_FLAG.Enabled = False
            End If
        Next

    End Sub

    Private Sub txtBoxGotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtEquipID.GotFocus
        Dim txtBox As TextBox = CType(sender, TextBox)
        txtBox.BackColor = Color.Cyan
        txtBox.SelectAll()
    End Sub

    Private Sub txtBoxLostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtEquipID.LostFocus
        Dim txtBox As TextBox = CType(sender, TextBox)
        txtBox.BackColor = Color.Yellow
        txtBox.Text = txtBox.Text.ToUpper
    End Sub
End Class